import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../i18n/locale_keys.dart';
import '../../services/config.dart';
import '../../style/space.dart';
import '../../utils/text.dart';
import '../../widget/button.dart';
import '../../widget/form/input.dart';
import '../../widget/icon.dart';
import '../../widget/image.dart';
import 'test_logic.dart';

class TestPage extends GetView<TestLogic> {
  TestPage({Key? key}) : super(key: key);
  final imgUrl = "https://ducafecat.oss-cn-beijing.aliyuncs.com/podcast/2024/08/36c15e6f46e96d85d56097424df1a26a.png";

  @override
  Widget build(BuildContext context) {
    return GetBuilder(builder: (_){
      return Scaffold(
        body: Column(
          children: [Text(ConfigService.to.version),
            Text(LocaleKeys.stylesTitle.tr),
            ElevatedButton(onPressed: (){
              controller.onLanguageSelected();
            }, child: Text("点击切换语言,当前语言:${ConfigService.to.locale.toLanguageTag()}")),
            const SizedBox(height: 20,),
            ElevatedButton(onPressed: (){
              controller.onThemeSelected("dark");
            }, child: const Text("切换成黑色主题")),
            const SizedBox(height: 10,),
            ElevatedButton(onPressed: (){
              controller.onThemeSelected("light");
            }, child: const Text("切换成亮色主题")),
            const SizedBox(height: 50,),
            const TextWidget.h1("测试一下字体封装，这个是封装的h1字体"),
            const TextWidget.h2("测试一下字体封装，这个是封装的h2字体"),
            const SizedBox(height: 20,),
            ImageWidget.img(imgUrl,width: 30,height: 30,),
            const IconWidget.icon(
              Icons.account_balance,
              size: 24,
              isDot: true,),
            const ButtonWidget.primary("text"),
            SizedBox(height: 50.w,),
            _buildView()
          ],
        ),
      );
    },
    init: TestLogic(),);
  }


  // 主视图
  Widget _buildView() {
    return Form(
        key: controller.formKey,
        child: <Widget>[
          // 账号
          InputFormFieldWidget(
            labelText: "账号",
            tipText: "输入账号或者登录Email",
            controller: controller.usernameController,
            placeholder: "请输入账号",
            prefix: const Icon(Icons.person),
            suffix: const Icon(Icons.done),
          ),

          // 密码
          InputFormFieldWidget(
            labelText: "密码",
            tipText: "密码长度需要大于6位",
            controller: controller.passwordController,
            placeholder: "请输入密码",
            prefix: const Icon(Icons.password),
            obscureText: true,
          ),

          // 提交按钮
          <Widget>[
            ButtonWidget.primary("提交", onTap: () {
              if (controller.formKey.currentState!.validate()) {
                Get.snackbar("Form", "submit");
              }
            }),
            ButtonWidget.secondary("返回", onTap: () => Get.back()),
          ].toRowSpace(
            mainAxisSize: MainAxisSize.min,
          ),

          // end
        ].toColumnSpace(
          crossAxisAlignment: CrossAxisAlignment.start,
        )).paddingAll(AppSpace.page).scrollable();
  }

}
